Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize asset paths before passing them to the loader #223

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

mxgrey
Copy link
Collaborator

@mxgrey mxgrey commented Jun 6, 2024

The bevy asset loader has a very unfortunate behavior of panicking if it receives an asset path with invalid syntax.

To prevent that I've changed the implementation of AssetSource from providing From<&AssetSource> for String to TryFrom<&AssetSource> for String, forcing us to verify that the asset source can be converted into an asset path with correct syntax before we pass it along to the bevy asset loader.

There are some cases where we just want to get any string out of the asset source and don't need it to have valid syntax, so for that I created an unsafe AssetSource method that simply does what the String conversion used to do. But this forces us to use unsafe and verify that we don't need valid syntax before using it.

To A/B test the panicking behavior, you can simply load up the demo world, select anything with a texture (e.g. wall or floor) and type one colon : anywhere in the asset source path. On the current main that will immediately make it panic. With this PR it should never panic; instead it will log an error to the console.

Signed-off-by: Michael X. Grey <[email protected]>
@mxgrey mxgrey merged commit 66c1603 into main Jun 7, 2024
5 checks passed
@mxgrey mxgrey deleted the sanitize_asset_paths branch June 7, 2024 05:26
reuben-thomas pushed a commit to reuben-thomas/rmf_site that referenced this pull request Jun 17, 2024
reuben-thomas pushed a commit to reuben-thomas/rmf_site that referenced this pull request Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants